package la.iok.hzsvn.lewin.movie.operation.controller;

import la.iok.hzsvn.lewin.movie.core.Token;
import la.iok.hzsvn.lewin.movie.operation.model.ChargeOrderParam;
import la.iok.hzsvn.lewin.movie.operation.model.ChargeOrderVo;
import la.iok.hzsvn.lewin.movie.operation.model.ChargePrepareRes;
import la.iok.hzsvn.lewin.movie.operation.service.ChargeOrderService;
import la.iok.hzsvn.lewin.mybatis.model.PageVo;
import la.iok.hzsvn.share.response.OperatorResponse;
import la.iok.hzsvn.share.response.OperatorResponses;
import la.iok.hzsvn.share.response.SingleDataResponse;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("chargeOrders")
public class ChargeOrderController {
    private final ChargeOrderService chargeOrderService;

    public ChargeOrderController(ChargeOrderService chargeOrderService) {
        this.chargeOrderService = chargeOrderService;
    }

    @PostMapping
    public SingleDataResponse<ChargePrepareRes> save(@RequestHeader Token token, @RequestBody ChargeOrderParam param){
        return new SingleDataResponse<>(chargeOrderService.save(token,param));
    }

    @GetMapping
    public SingleDataResponse<PageVo<ChargeOrderVo>> page(@RequestHeader Token token,String orderColumn, String order,
                                                          int page, int limit, Long orgUnitId, Long roomId){
        return new SingleDataResponse<>(chargeOrderService.page(token,page,limit,orderColumn,order,orgUnitId,roomId));
    }

    @PutMapping("{id}")
    public OperatorResponse close(@RequestHeader Token token, @PathVariable Long id){
        chargeOrderService.close(token,id);
        return OperatorResponses.success();
    }
    @GetMapping("{id}")
    public SingleDataResponse<ChargeOrderVo> order(@RequestHeader Token token, @PathVariable Long id){
        return new SingleDataResponse<>(chargeOrderService.queryWithUpdate(token,id));
    }
}
